<?php
namespace jy_weishop_en;
defined('BY_JYA') or exit('error');
/*
	消息提醒
*/
class notice extends \plugin{
	public function gettpl_data($orderid,$type=0){//type=0表单订单，type=1
		$shopset=$this->plugin_setting('shopset');
		$order=pdo_get('jy_weishop_order',array('id'=>$orderid));
		$member=model('core/member')->detail($order['mid'],array('credit1','credit2','mobile','avatar','nickname'));
		$goods=pdo_getall('jy_weishop_order_goods',array('orderid'=>$order_id));
		if($goods){
			$str = '';
			foreach($goods as &$g){
				$g['title']=pdo_getcolumn('jy_weishop_goods',array('id'=>$g['goodsid']),'title');
				if($g['optionid']){
						$option_goods=pdo_get('jy_weishop_goods_option',array('id'=>$g['optionid'],'uniacid'=>$_SESSION['uniacid']),array('price','stock','specs'));
						if(!$option_goods){
							//exi('指定规格的商品不存在！','error','goback');
						}
						$g['total']=$option_goods['stock'];
						$g['price']=$option_goods['price'];
						$specs = explode("_", $option_goods['specs']);
						$specsall = pdo_getall('jy_weishop_goods_spec_item',array('id'=>$specs,'uniacid'=>$_SESSION['uniacid']),array('id','title'),'','paixu asc');
						if($specsall){
							$optiontitle='';
							foreach($specsall as $k=>&$sp){
								if($k==0){
									$optiontitle .=$sp['title'];
								}else{
									$optiontitle .='，'.$sp['title'];
								}
							}
						}
						$g['optiondata']= $optiontitle;
						$str .= $g['title']."--规格如下：\n";
						$money = $g['price'] * $g['total'];
						$str .= '['.str_pad($g['title'].']', '23', ' ', STR_PAD_RIGHT);
						$str .= ''.str_pad($g['total'], '5', ' ', STR_PAD_RIGHT);
						$str .= ''. number_format($money, 2) . "元\n";
				}else{
						$money = $g['price'] * $g['total'];
						$str .= ''.str_pad($g['title'], '26', ' ', STR_PAD_RIGHT);
						$str .= ''.str_pad($g['total'], '5', ' ', STR_PAD_RIGHT);
						$str .= ''. number_format($money, 2) . "元\n";
				}
			}
		}
		$goodsinfo = "名称　             数量    单价\n";
		$goodsinfo .= $str;
		$goodsinfo .= "---------------------------------\n";
		$goodsname=$goods[0]['title'];
		$goodsnum=count($goods);
		$address=pdo_get('core_address',array('id'=>$order['addressid']));
		$address['pcd']=json_decode($address['pcd'],true);
		$addressinfo=$address['pcd']['province'].' '.$address['pcd']['city'].' '.$address['pcd']['district'].' '.$address['pcd']['street'].' '.$address['pcd']['streetNumber'].' '.$address['address'];
		$store=pdo_get('jy_weishop_store',array('id'=>$order['storeid']));
		$store['pcd']=json_decode($store['pcd'],true);
		$storeaddress=$store['pcd']['province'].' '.$store['pcd']['city'].' '.$store['pcd']['district'].' '.$store['pcd']['street'].' '.$store['pcd']['streetNumber'].' '.$store['address'];
		$selfinfo=pdo_get('jy_weishop_order_self',array('orderid'=>$orderid));
		$datas = array(
			array('name' => '商城名称', 'value' => $shopset['title']),
			array('name' => '粉丝昵称', 'value' => $member['nickname']),
			array('name' => '订单号', 'value' => $order['ordersn']),
			array('name' => '订单金额', 'value' => $order['price']),
			array('name' => '订单状态', 'value' => $this->order_status[$order['status']]),
			array('name' => '运费', 'value' => $order['dispatchprice']),
			array('name' => '商品详情', 'value' => $goodsinfo),
			array('name' => '快递公司', 'value' => $order['expresscom']),
			array('name' => '快递单号', 'value' => $order['expresssn']),
			array('name' => '收件人', 'value' => $order['realname']),
			array('name' => '购买者姓名', 'value' => $address['name']),
			array('name' => '购买者电话', 'value' => $address['mobile']),
			array('name' => '收货地址', 'value' => $addressinfo),
			array('name' => '下单时间', 'value' => date('Y-m-d H:i', $order['createtime'])),
			array('name' => '支付时间', 'value' => date('Y-m-d H:i', $order['paytime'])),
			array('name' => '发货时间', 'value' => date('Y-m-d H:i', $order['sendtime'])),
			array('name' => '收货时间', 'value' => date('Y-m-d H:i', $order['finishtime'])),
			array('name' => '取消时间', 'value' => date('Y-m-d H:i', $order['canceltime'])),
			array('name' => '门店', 'value' => (!(empty($store)) ? $store['title'] : '')),
			array('name' => '门店地址', 'value' => (!(empty($store)) ? $storeaddress : '')),
			array('name' => '门店联系人', 'value' => (!(empty($store)) ? $store['realname'] . '/' . $store['mobile'] : '')),
			array('name' => '门店营业时间', 'value' => (!(empty($store)) ? ((empty($store['onlinetime']) ? '全天' : $store['onlinetime'])) : '')),
			array('name' => '虚拟物品自动发货内容', 'value' => $order['virtualsend_info']),
			array('name' => '虚拟卡密自动发货内容', 'value' => $order['virtual_str']),
			array('name' => '自提码', 'value' => $selfinfo['number']),
			array('name' => '备注信息', 'value' => $order['remark']),
			array('name' => '商品数量', 'value' => $goodsnum),
			array('name' => '商品名称', 'value' => $goodsname),
			array('name' => '现金收入', 'value' => $fenxiaofee),
			array('name' => '积分收入', 'value' => $fenxiaocrx),
			array('name' => '当前时间', 'value' => date('Y-m-d H:i:s',time())),
		);
		return $datas;
	}
	public function notice_create2buyer($order,$url=''){
		//发送订单生成通知给买方		
		$template_id=cfc('account')->get_tpl_template_id('OPENTM200746866','订单提交成功通知');
		if($_SESSION['wxapp_id']){
			$wxapptemplate_id=cfc('wxapp_api')->get_tpl_template_id('3534',[1,2,3,4],'create2buyer','订单提交成功通知','jy_weishop');
		}
		$shopset=$this->plugin_setting('shopset');
		$message=array(
			'first'=>array('value'=>'订单提交成功通知',"color" => "#4a5077"),
			'keyword1'=>array('value'=>$shopset['title']?:'平台商城',"color" => "#4a5077"),
			'keyword2'=>array('value'=>date('Y-m-d H:i:s',$order['createtime']),"color" => "#4a5077"),
			'keyword3'=>array('value'=>$order['goods']['0']['title'].'等商品',"color" => "#4a5077"),
			'keyword4'=>array('value'=>price($order['price']),"color" => "#4a5077"),
			'remark'=>array('value'=>'谢谢惠顾！欢迎您的再次到来！点击“详情”查看订单信息。',"color" => "#4a5077"),
		);
		$statustitle=$order['status']==1?'已下单':'待支付';
		$wxappmsg=array(
			array('value'=>$order['ordersn']),
			array('value'=>$this->order_status[$order['status']]),
			array('value'=>$order['goods']['0']['title']),
			array('value'=>price($order['price'])),
		);
		if(!$url){
			$url=custom_url('jy_weishop_en/order.detail//id='.$order['id'],true);	
		}
		if(method_exists(cfc('account'),'sendtwoNotice')){
			cfc('account')->sendtwoNotice($order['mid'],$template_id,$message,$url,'create2buyer','jy_weishop',$order['id']);
		}
		if($_SESSION['wxapp_id'] && $wxapptemplate_id){
			$template_id=cfc('wxapp_api')->checktplNotice($order['mid'],$wxapptemplate_id,$wxappmsg,$url,'create2buyer','jy_weishop',$order['id']);
		}
		
	}
	public function notice_cancel2buyer($order){
		//发送订单取消通知给买方		
		$template_id=cfc('account')->get_tpl_template_id('TM00850','订单取消通知');
		$address_str=model('core/member')->get_address_str($order['addressid']);
		$message=array(
			'first'=>array('value'=>'订单取消通知',"color" => "#4a5077"),
			'orderProductPrice'=>array('value'=>$order['price'],"color" => "#4a5077"),
			'orderProductName'=>array('value'=>$order['goods']['0']['title'],"color" => "#4a5077"),
			'orderAddress'=>array('value'=>$address_str,"color" => "#4a5077"),
			'orderName'=>array('value'=>$order['ordersn'],"color" => "#4a5077"),
			'remark'=>array('value'=>'点击“详情”查看详细处理信息，如有疑问可直接联系客服。',"color" => "#4a5077"),
		);
		$url=custom_url('jy_weishop_en/order.detail//id='.$order['id'],true);
		if(method_exists(cfc('account'),'sendtwoNotice')){
			cfc('account')->sendtwoNotice($order['mid'],$template_id,$message,$url,'cancel2buyer','jy_weishop',$order['id']);
		}
		
	}
	public function notice_pay2buyer($order,$url=''){
		//发送订单支付通知给买方
		$shopset=$this->plugin_setting('shopset');
		$template_id=cfc('account')->get_tpl_template_id('OPENTM204987032','订单支付成功通知');	
		$_SESSION['wxapp_id']=$_SESSION['wxapp_id']?:$order['wxapp_id'];
		if($_SESSION['wxapp_id']){
			$wxapptemplate_id=cfc('wxapp_api')->get_tpl_template_id('30808',[1,13,7,5,8],'pay2buyer','订单支付成功通知','jy_weishop');
		}
		$is_pays =array('0'=>'未支付','1'=>'已支付');
		$paytitle=($order['status']==1 && $order['ispay']!=1)?'货到付款':'线上支付';
		$statustitle=$is_pays[$order['ispay']].'-('.$paytitle.')';
		$shopname = $order['merchname']?:$shopset['title'];
		$message=array(
			'first'=>array('value'=>'订单支付成功通知',"color" => "#4a5077"),
			'keyword1'=>array('value'=>$order['ordersn'],"color" => "#4a5077"),
			'keyword2'=>array('value'=>$statustitle,"color" => "#4a5077"),
			'keyword3'=>array('value'=>date('Y-m-d H:i:s',$order['paytime']),"color" => "#4a5077"),
			'keyword4'=>array('value'=>$shopname,"color" => "#4a5077"),
			'keyword5'=>array('value'=>$order['price'],"color" => "#4a5077"),
			'remark'=>array('value'=>'谢谢惠顾！欢迎您的再次到来！点击“详情”查看订单信息。',"color" => "#4a5077"),
		);
		$wxappmsg=array(
			array('value'=>$order['ordersn']),
			array('value'=>$is_pays[$order['ispay']]),
			array('value'=>date('Y-m-d H:i:s',$order['paytime'])),
			array('value'=>$shopname),
			array('value'=>$order['price']),
		);
		if(!$url){
			$url='jy_weishop_en/order.detail//id='.$order['id'];
		}
		$url=custom_url($url,true);
		cfc('account')->sendtwoNotice($order['mid'],$template_id,$message,$url,'pay2buyer','jy_weishop',$order['id']);
		if($_SESSION['wxapp_id'] && $wxapptemplate_id){
			$url='/jy_weishop_en/order/detail/index?id='.$order['id'];
			$template_id=cfc('wxapp_api')->checktplNotice($order['mid'],$wxapptemplate_id,$wxappmsg,$url,'pay2buyer','jy_weishop',$order['id']);
		}
	}
	public function notice_send2buyer($order,$url=''){
		//发送订单发货通知给买方
		$template_id=cfc('account')->get_tpl_template_id('OPENTM409831570','订单发货通知');
		$wxapp_id=$order['wxapp_id'];
		if(!$_SESSION['wxapp_id'] && !$wxapp_id){
			$wxapp_id=cfc('fans')->get_appid($order['mid'],1);
		}
		if($_SESSION['wxapp_id'] || $wxapp_id){
			$wxapptemplate_id=cfc('wxapp_api',$wxapp_id)->get_tpl_template_id('30766',[1,2,4,5,9],'send2buyer','订单发货通知','jy_weishop');
		}	
		$address_str=model('core/member')->get_address_str($order['addressid']);
		$message=array(
			'first'=>array('value'=>'您的商品已发货，请及时查收！',"color" => "#4a5077"),
			'keyword1'=>array('value'=>$order['goods']['0']['title'].'等商品',"color" => "#4a5077"),
			'keyword2'=>array('value'=>$order['ordersn'],"color" => "#4a5077"),
			'keyword3'=>array('value'=>$this->model('model')->express_types()[$order['express']['express_id']]['name'],"color" => "#4a5077"),
			'keyword4'=>array('value'=>$order['express']['expresssn'],"color" => "#4a5077"),
			'keyword5'=>array('value'=>$address_str,"color" => "#4a5077"),
			'remark'=>array('value'=>'请耐心等候！',"color" => "#4a5077"),
		);
		$wxappmsg=array(
			array('value'=>$order['goods']['0']['title']),
			array('value'=>$order['ordersn']),
			array('value'=>$this->model('model')->express_types()[$order['express']['express_id']]['name']),
			array('value'=>$order['express']['expresssn']),
			array('value'=>$address_str),
		);
		if(!$url){
			$url='jy_weishop_en/order.detail//id='.$order['id'];
		}
		$url=custom_url($url,true);
		cfc('account')->sendtwoNotice($order['mid'],$template_id,$message,$url,'send2buyer','jy_weishop',$order['id']);
		if($_SESSION['wxapp_id'] && $wxapptemplate_id){
			$url='/jy_weishop_en/order/detail/index?id='.$order['id'];
			$template_id=cfc('wxapp_api',$wxapp_id)->checktplNotice($order['mid'],$wxapptemplate_id,$wxappmsg,$url,'send2buyer','jy_weishop',$order['id']);
		}
	}
	public function notice_pei2buyer($order,$url=''){
		//订单配送提醒
		$template_id=cfc('account')->get_tpl_template_id('OPENTM405637366','订单配送提醒');
		$wxapp_id=$order['wxapp_id'];
		if(!$_SESSION['wxapp_id'] && !$wxapp_id){
			$wxapp_id=cfc('fans')->get_appid($order['mid'],1);
		}
		if($_SESSION['wxapp_id'] || $wxapp_id){
			$wxapptemplate_id=cfc('wxapp_api',$wxapp_id)->get_tpl_template_id('31339',[2,3],'pei2buyer','订单配送提醒','jy_weishop');
		}	
		$message=array(
			'first'=>array('value'=>'您好!您的商品正在配送中,请您保持手机的通畅。',"color" => "#4a5077"),
			'keyword1'=>array('value'=>$order['ordersn'],"color" => "#4a5077"),
			'keyword2'=>array('value'=>date('Y-m-d',time()),"color" => "#4a5077"),
			'keyword3'=>array('value'=>$order['goods'][0]['title'],"color" => "#4a5077"),
			'remark'=>array('value'=>'请耐心等候！如有疑问请联系在线客服！',"color" => "#4a5077"),
		);
		$wxappmsg=array(
			array('value'=>date('Y-m-d H:i:s',$order['paytime'])),
			array('value'=>$order['goods'][0]['title']),
		);
		if(!$url){
			$url='jy_weishop_en/order.detail//id='.$order['id'];
		}
		$url=custom_url($url,true);
		cfc('account')->sendtwoNotice($order['mid'],$template_id,$message,$url,'pei2buyer','jy_weishop',$order['id']);
		if($_SESSION['wxapp_id'] && $wxapptemplate_id){
			$url='/jy_weishop_en/order/detail/index?id='.$order['id'];
			$template_id=cfc('wxapp_api',$wxapp_id)->checktplNotice($order['mid'],$wxapptemplate_id,$wxappmsg,$url,'pei2buyer','jy_weishop',$order['id']);
		}
	}
	public function notice_vsend2buyer($order,$url=''){
		//卡密自动发货通知发送订单发货通知给买方
		$template_id=cfc('account')->get_tpl_template_id('OPENTM207793687','自动发货通知');
		$remark="发货信息：\n";
		$remark .='联系人：'.$order['nickname']."\n";
		$remark .='联系手机：'.$order['mobile']."\n";
		//$remark .=$order['virtualinfo'];
		$message=array(
			'first'=>array('value'=>'您的商品已自动发货，请及时查收！',"color" => "#4a5077"),
			'keyword1'=>array('value'=>$order['goods']['0']['title'].'等商品',"color" => "#4a5077"),
			'keyword2'=>array('value'=>$order['ordersn'],"color" => "#4a5077"),
			'keyword3'=>array('value'=>$order['price'],"color" => "#4a5077"),
			'keyword4'=>array('value'=>$order['virtualinfo'],"color" => "#4a5077"),
			'remark'=>array('value'=>$remark,"color" => "#4a5077"),
		);
		if(!$url){
			$url='jy_weishop_en/order.detail//id='.$order['id'];
		}
		$url=custom_url($url,true);
		cfc('account')->sendtwoNotice($order['mid'],$template_id,$message,$url,'vsend2buyer','jy_weishop',$order['id']);
	}
	public function notice_sendinfo2buyer($order,$url=''){
		//卡密自动发货通知发送订单发货通知给买方
		$template_id=cfc('account')->get_tpl_template_id('OPENTM202314085','自动发货通知');
		$remark="发货信息：\n";
		$remark .='联系人：'.$order['nickname']."\n";
		$remark .='联系手机：'.$order['mobile']."\n";
		$remark .=$order['virtualinfo'];
		$message=array(
			'first'=>array('value'=>'您的商品已自动发货，请及时查收！',"color" => "#4a5077"),
			'keyword1'=>array('value'=>$order['ordersn'],"color" => "#4a5077"),
			'keyword2'=>array('value'=>$order['goods']['0']['title'].'等商品',"color" => "#4a5077"),
			'keyword3'=>array('value'=>date('Y-m-d H:i:s',$order['createtime']),"color" => "#4a5077"),
			'keyword4'=>array('value'=>date('Y-m-d H:i:s',$order['sendtime']),"color" => "#4a5077"),
			'keyword5'=>array('value'=>date('Y-m-d H:i:s',$order['finishtime']),"color" => "#4a5077"),
			'remark'=>array('value'=>$remark,"color" => "#4a5077"),
		);
		if(!$url){
			$url='jy_weishop_en/order.detail//id='.$order['id'];
		}
		$url=custom_url($url,true);
		cfc('account')->sendtwoNotice($order['mid'],$template_id,$message,$url,'sendinfo2buyer','jy_weishop',$order['id']);
	}
	public function notice_receive2buyer($order){
		//发送订单收货通知给买方
		$template_id=cfc('account')->get_tpl_template_id('OPENTM202314085','订单确认收货通知');
		$wxapp_id=$order['wxapp_id'];
		if(!$_SESSION['wxapp_id'] && !$wxapp_id){
			$wxapp_id=cfc('fans')->get_appid($order['mid'],1);
		}
		if($_SESSION['wxapp_id'] || $wxapp_id){
			$wxapptemplate_id=cfc('wxapp_api')->get_tpl_template_id('31042',[1,2,4,10,7],'receive2buyer','订单确认收货通知','jy_weishop');
		}
		$message=array(
			'first'=>array('value'=>'亲：您在我们商城买的宝贝已经确认收货。',"color" => "#4a5077"),
			'keyword1'=>array('value'=>$order['ordersn'],"color" => "#4a5077"),
			'keyword2'=>array('value'=>$order['goods']['0']['title'].'等商品',"color" => "#4a5077"),
			'keyword3'=>array('value'=>date('Y-m-d H:i:s',$order['createtime']),"color" => "#4a5077"),
			'keyword4'=>array('value'=>date('Y-m-d H:i:s',$order['sendtime']),"color" => "#4a5077"),
			'keyword5'=>array('value'=>date('Y-m-d H:i:s',$order['finishtime']),"color" => "#4a5077"),
			'remark'=>array('value'=>'感谢您的支持与厚爱。',"color" => "#4a5077"),
		);
		$wxappmsg=array(
			array('value'=>$order['ordersn']),
			array('value'=>$order['goods']['0']['title']),
			array('value'=>date('Y-m-d H:i:s',$order['createtime'])),
			array('value'=>date('Y-m-d H:i:s',$order['sendtime'])),
			array('value'=>date('Y-m-d H:i:s',$order['finishtime'])),
		);
		$url=custom_url('jy_weishop_en/order.detail//id='.$order['id'],true);
		cfc('account')->sendtwoNotice($order['mid'],$template_id,$message,$url,'receive2buyer','jy_weishop',$order['id']);
		if($_SESSION['wxapp_id'] && $wxapptemplate_id){
			$url='/jy_weishop_en/order/detail/index?id='.$order['id'];
			$template_id=cfc('wxapp_api',$wxapp_id)->checktplNotice($order['mid'],$wxapptemplate_id,$wxappmsg,$url,'receive2buyer','jy_weishop',$order['id']);
		}
	}
	public function notice_create2seller($order,$seller_id){
		//发送订单生成通知给卖方
		$template_id=cfc('account')->get_tpl_template_id('OPENTM205213550','订单生成通知');
		$message=array(
			'first'=>array('value'=>'订单生成通知',"color" => "#4a5077"),
			'keyword1'=>array('value'=>date('Y-m-d H:i:s',$order['createtime']),"color" => "#4a5077"),
			'keyword2'=>array('value'=>$order['goods']['0']['title'].'等商品',"color" => "#4a5077"),
			'keyword3'=>array('value'=>$order['ordersn'],"color" => "#4a5077"),
			'remark'=>array('value'=>'请及时处理！',"color" => "#4a5077"),
		);
		if(method_exists(cfc('account'),'sendtwoNotice')){
			cfc('account')->sendtwoNotice($seller_id,$template_id,$message,'','create2seller','jy_weishop',$order['id']);
		}
	}
	public function notice_cancel2seller($order,$seller_id){
		//发送订单取消通知给卖方		
		$template_id=cfc('account')->get_tpl_template_id('OPENTM406411654','订单取消通知卖方');
		$message=array(
			'first'=>array('value'=>'订单取消通知',"color" => "#4a5077"),
			'keyword1'=>array('value'=>$order['ordersn'],"color" => "#4a5077"),
			'keyword2'=>array('value'=>$order['goods']['0']['title'].'等商品',"color" => "#4a5077"),
			'remark'=>array('用户已取消订单！',"color" => "#4a5077"),
		);		
		cfc('account')->sendtwoNotice($seller_id,$template_id,$message,$url,'cancel2seller','jy_weishop',$order['id']);		
	}
	public function notice_pay2seller($order,$seller_id,$url=''){
		//发送订单支付通知给卖方
		$template_id=cfc('account')->get_tpl_template_id('OPENTM207498902','订单支付成功通知卖方');
		$wxapp_id=$order['wxapp_id'];
		if(!$_SESSION['wxapp_id'] && !$wxapp_id){
			$wxapp_id=cfc('fans')->get_appid($seller_id,1);
		}
		if($_SESSION['wxapp_id'] || $wxapp_id){
			$wxapptemplate_id=cfc('wxapp_api',$wxapp_id)->get_tpl_template_id('30808',[6,1,3,4],'pay2seller','订单支付成功通知卖方','jy_weishop');
		}
		$address_str=model('core/member')->get_address_str($order['addressid'],'',true);
		$member=model('core/member')->detail($order['mid'],array('credit1','credit2','mobile','avatar','nickname'));
		$message=array(
			'first'=>array('value'=>'用户已在线支付该笔订单，请知悉。',"color" => "#4a5077"),
			'keyword1'=>array('value'=>$member['nickname'],"color" => "#4a5077"),
			'keyword2'=>array('value'=>$order['ordersn'],"color" => "#4a5077"),
			'keyword3'=>array('value'=>$order['price'],"color" => "#4a5077"),
			'keyword4'=>array('value'=>$order['goods']['0']['title'].'等商品',"color" => "#4a5077"),
			'remark'=>array('value'=>'请及时安排处理！',"color" => "#4a5077"),
		);
		$wxappmsg=array(
			array('value'=>$member['nickname']),
			array('value'=>$order['ordersn']),
			array('value'=>$order['price']),
			array('value'=>$order['goods']['0']['title']),
		);
		$url=$url?:'jy_weishop_en/member.index/';
		$url2=custom_url($url,true);
		cfc('account')->sendtwoNotice($seller_id,$template_id,$message,$url2,'pay2seller','jy_weishop',$order['id']);
		if($_SESSION['wxapp_id'] && $wxapptemplate_id){
			$url2=wxapp_links($url);
			$template_id=cfc('wxapp_api',$wxapp_id)->checktplNotice($seller_id,$wxapptemplate_id,$wxappmsg,$url2,'pay2seller','jy_weishop',$order['id']);
		}
	}
	public function notice_send2seller($order,$seller_id){
		//发送订单发货通知给卖方
		$template_id=cfc('account')->get_tpl_template_id('OPENTM202243318','订单发货通知卖方');
		$wxapp_id=$order['wxapp_id'];
		if(!$_SESSION['wxapp_id'] && !$wxapp_id){
			$wxapp_id=cfc('fans')->get_appid($seller_id,1);
		}
		if($_SESSION['wxapp_id'] || $wxapp_id){
			$wxapptemplate_id=cfc('wxapp_api',$wxapp_id)->get_tpl_template_id('30766',[1,2,4,5,9],'send2seller','订单发货通知卖方','jy_weishop');
		}
		$message=array(
			'first'=>array('value'=>'订单已发货',"color" => "#4a5077"),
			'keyword1'=>array('value'=>$order['goods']['0']['title'].'等商品',"color" => "#4a5077"),
			'keyword2'=>array('value'=>$this->model('model')->express_types()[$order['express']['express_id']]['name'],"color" => "#4a5077"),
			'keyword3'=>array('value'=>$order['express']['expresssn'],"color" => "#4a5077"),
			'keyword4'=>array('value'=>$address_str,"color" => "#4a5077"),
			'remark'=>array('value'=>'详情请登陆后台查看！',"color" => "#4a5077"),
		);
		$wxappmsg=array(
			array('value'=>$order['ordersn']),
			array('value'=>$order['goods']['0']['title']),
			array('value'=>date('Y-m-d H:i:s',$order['createtime'])),
			array('value'=>date('Y-m-d H:i:s',$order['sendtime'])),
			array('value'=>date('Y-m-d H:i:s',$order['finishtime'])),
		);
		if(!$url){
			$url='jy_weishop_en/order.detail//id='.$order['id'];
		}
		$url=custom_url($url,true);
		cfc('account')->sendtwoNotice($seller_id,$template_id,$message,$url,'send2seller','jy_weishop',$order['id']);
		if($_SESSION['wxapp_id'] || $wxapp_id){
			$url='/jy_weishop_en/order/detail/index?id='.$order['id'];
			$template_id=cfc('wxapp_api',$wxapp_id)->checktplNotice($seller_id,$wxapptemplate_id,$wxappmsg,$url,'send2seller','jy_weishop',$order['id']);
		}
	}
	public function notice_receive2seller($order,$seller_id){
		//发送订单收货通知给卖方
		$template_id=cfc('account')->get_tpl_template_id('OPENTM202314085','订单确认收货通知卖方');
		$wxapp_id=$order['wxapp_id'];
		if($_SESSION['wxapp_id'] || $wxapp_id){
			$wxapptemplate_id=cfc('wxapp_api',$wxapp_id)->get_tpl_template_id('31042',[1,2,4,10,7],'receive2seller','订单发货通知卖方','jy_weishop');
		}
		$message=array(
			'first'=>array('value'=>'用户已确认收货！',"color" => "#4a5077"),
			'keyword1'=>array('value'=>$order['ordersn'],"color" => "#4a5077"),
			'keyword2'=>array('value'=>$order['goods']['0']['title'].'等商品',"color" => "#4a5077"),
			'keyword3'=>array('value'=>date('Y-m-d H:i:s',$order['createtime']),"color" => "#4a5077"),
			'keyword4'=>array('value'=>date('Y-m-d H:i:s',$order['finishtime']),"color" => "#4a5077"),
			'keyword5'=>array('value'=>date('Y-m-d H:i:s',$order['finishtime']),"color" => "#4a5077"),
			'remark'=>array('value'=>'详情请登陆后台查看！',"color" => "#4a5077"),
		);
		$wxappmsg=array(
			array('value'=>$order['ordersn']),
			array('value'=>$order['goods']['0']['title']),
			array('value'=>date('Y-m-d H:i:s',$order['createtime'])),
			array('value'=>date('Y-m-d H:i:s',$order['sendtime'])),
			array('value'=>date('Y-m-d H:i:s',$order['finishtime'])),
		);
		cfc('account')->sendtwoNotice($seller_id,$template_id,$message,'','receive2seller','jy_weishop',$order['id']);
		if($_SESSION['wxapp_id']){
			$template_id=cfc('wxapp_api',$wxapp_id)->checktplNotice($seller_id,$wxapptemplate_id,$wxappmsg,'','receive2seller','jy_weishop',$order['id']);
		}
	}
	public function notice_fenxiao_xiajiadd($mid,$agent_id){
		//分销新增队员提醒
		$template_id=cfc('account')->check_tpl_template('OPENTM207685059','jy_weishop','分销新增队员提醒');
		$userinfo=pdo_get('core_members',array('id'=>$mid),array('fromuser','nickname'));
		$message=array(
			'first'=>array('value'=>'您好，您的团队有新成员加入',"color" => "#4a5077"),
			'keyword1'=>array('title'=>'队员昵称','value'=>$userinfo['nickname'],"color" => "#4a5077"),
			'keyword2'=>array('title'=>'加入时间','value'=>date('Y-m-d H:i:s',time()),"color" => "#4a5077"),
			'remark'=>array('value'=>'您可以到我的团队管理后台，管理您的队员！',"color" => "#4a5077"),
		);
		if(!$url){
			$url='jy_commission/index/';
		}
		$url=custom_url($url,true);
		cfc('account')->sendtwoNotice($agent_id,$template_id,$message,$url,'fenxiao_xiajiadd','jy_weishop');
	}
	public function notice_fenxiao_feeadd($agent_id,$fee=0){
		//分销团队收入提醒
		$template_id=cfc('account')->check_tpl_template('OPENTM207497773','jy_weishop','分销团队收入提醒');
		$message=array(
			'first'=>array('value'=>'您好，你的队员刚刚为你带来收入如下，请及时查看。',"color" => "#4a5077"),
			'keyword1'=>array('title'=>'收入时间','value'=>date('Y-m-d H:i:s',time()),"color" => "#4a5077"),
			'keyword2'=>array('title'=>'收入金额','value'=>$fee,"color" => "#4a5077"),
			'keyword3'=>array('title'=>'收入积分','value'=>0,"color" => "#4a5077"),
			'remark'=>array('value'=>'点击可查看收入详情。',"color" => "#4a5077"),
		);
		if(!$url){
			$url='jy_commission/index/';
		}
		$url=custom_url($url,true);
		cfc('account')->sendtwoNotice($agent_id,$template_id,$message,$url,'fenxiao_feeadd','jy_weishop');
	}
	public function notice_upprice($order){
		//修改价格通知给买方
		$template_id=cfc('account')->get_tpl_template_id('OPENTM203998003','订单改价通知');
		$message=array(
			'first'=>array('value'=>'卖家已经修改价格，请您确认价格后支付！',"color" => "#4a5077"),
			'keyword1'=>array('value'=>$order['ordersn'],"color" => "#4a5077"),
			'keyword2'=>array('value'=>$order['goods']['0']['title'],"color" => "#4a5077"),
			'keyword3'=>array('value'=>date('Y-m-d H:i:s',$order['createtime']),"color" => "#4a5077"),
			'keyword5'=>array('value'=>$this->order_status[$order['status']],"color" => "#4a5077"),
			'remark'=>array('value'=>'请您尽快支付！点击“详情”查看订单信息。',"color" => "#4a5077"),
		);
		$url=custom_url('jy_weishop_en/order.detail//id='.$order['id'],true);
		cfc('account')->sendtwoNotice($order['mid'],$template_id,$message,$url,'upprice','jy_weishop',$order['id']);
	}
	public function notice_queuecall($queue,$url=''){
		//排号通知
		$template_id=cfc('account')->get_tpl_template_id('OPENTM205984119','排号通知');
		$lastnumber=pdo_count('jy_weishop_queue_member',array('uniacid'=>$_SESSION['uniacid'],'status'=>0,'createtime <'=>$queue['createtime']),'id');
		$message=array(
			'first'=>array('value'=>'排号有新消息，感谢等待！！',"color" => "#4a5077"),
			'keyword1'=>array('value'=>$queue['number'],"color" => "#4a5077"),
			'keyword2'=>array('value'=>date('Y-m-d H:i:s',$queue['createtime']),"color" => "#4a5077"),
			'keyword3'=>array('value'=>$lastnumber.'桌',"color" => "#4a5077"),
			'remark'=>array('value'=>'听到叫号后，请到迎宾台。过号会被作废，需重新取号！',"color" => "#4a5077"),
		);
		if($queue['action']){
			$url=custom_url($queue['action'],true);
		}
		cfc('account')->sendtwoNotice($queue['mid'],$template_id,$message,$url,'queuecall','jy_weishop',$queue['id']);
	}
	public function notice_groupfinish_dingcan($dingorder,$url=''){
		//参团成功,定价支付成功
		$template_id=cfc('account')->get_tpl_template_id('OPENTM413583910','参团成功通知');
		$message=array(
			'first'=>array('value'=>'你已成功参团，谢谢！',"color" => "#4a5077"),
			'keyword1'=>array('value'=>$dingorder['goodstitle'],"color" => "#4a5077"),
			'keyword2'=>array('value'=>date('Y-m-d H:i:s',$dingorder['createtime']),"color" => "#4a5077"),
			'remark'=>array('value'=>'快邀请好友来参团吧！点击“查看详情”。',"color" => "#4a5077"),
		);
		//$url=custom_url('jy_weishop_en/order.detail//id='.$dingorder['orderid'],true);
		cfc('account')->sendtwoNotice($dingorder['mid'],$template_id,$message,$url,'groupfinish','jy_weishop',$dingorder['orderid']);
	}
	public function notice_groupfinish_ding($dingorder,$url=''){
		//拼团成功,定价支付成功
		$template_id=cfc('account')->get_tpl_template_id('OPENTM406772650','拼团成功通知');
		$message=array(
			'first'=>array('value'=>'您的拼单已经成功，请尽快支付尾款！',"color" => "#4a5077"),
			'keyword1'=>array('value'=>$dingorder['goodstitle'],"color" => "#4a5077"),
			'keyword2'=>array('value'=>$dingorder['price'],"color" => "#4a5077"),
			'keyword3'=>array('value'=>$dingorder['orderprice'],"color" => "#4a5077"),
			'remark'=>array('value'=>'补齐剩余费用，就能获得宝贝哦！点击“详情”支付尾款。',"color" => "#4a5077"),
		);
		//$url=custom_url('jy_weishop_en/order.detail//id='.$dingorder['orderid'],true);
		cfc('account')->sendtwoNotice($dingorder['mid'],$template_id,$message,$url,'groupfinish','jy_weishop',$dingorder['orderid']);
	}
	public function notice_groupfinish_fan($order,$fanfee,$msg=''){
		//返现
		$template_id=cfc('account')->get_tpl_template_id('OPENTM207327044','获得返现通知');
		$message=array(
			'first'=>array('value'=>'恭喜您，获得返现奖励！',"color" => "#4a5077"),
			'keyword1'=>array('value'=>'参团奖励',"color" => "#4a5077"),
			'keyword2'=>array('value'=>$fanfee,"color" => "#4a5077"),
			'keyword3'=>array('value'=>$msg?:'返现到余额',"color" => "#4a5077"),
			'remark'=>array('value'=>'奖励金已打款到您的余额，感谢您的支持。',"color" => "#4a5077"),
		);
		if(is_array($order) && $order['mid']){
			cfc('account')->sendtwoNotice($order['mid'],$template_id,$message,$url,'groupfinish','jy_weishop',$order['orderid']);
		}
	}
	public function notice_sendcoupon($order,$url=''){
		//发送优惠券
		$template_id=cfc('account')->get_tpl_template_id('OPENTM200605630','优惠券通知');
		$message=array(
			'first'=>array('value'=>'恭喜您，获得优惠券！！',"color" => "#4a5077"),
			'keyword1'=>array('value'=>'请您点击查看',"color" => "#4a5077"),
			'remark'=>array('value'=>'点击“详情”查看信息。',"color" => "#4a5077"),
		);
		$url=custom_url('jy_weishop_en/coupon.myindex/',true);
		cfc('account')->sendtwoNotice($order['mid'],$template_id,$message,$url,'groupfinish','jy_weishop',$order['id']);
	}
	public function notice_groupfinish($order,$url=''){
		//拼团成功
		$template_id=cfc('account')->get_tpl_template_id('OPENTM406772650','拼团成功通知');
		$message=array(
			'first'=>array('value'=>'您的拼单已经成功，我们会尽快安排发货！',"color" => "#4a5077"),
			'keyword1'=>array('value'=>$order['ordersn'],"color" => "#4a5077"),
			'keyword2'=>array('value'=>$order['price'],"color" => "#4a5077"),
			'keyword5'=>array('value'=>'0.00',"color" => "#4a5077"),
			'remark'=>array('value'=>'谢谢惠顾！欢迎您的再次到来！点击“详情”查看拼单信息。',"color" => "#4a5077"),
		);
		//$url=custom_url('jy_weishop_en/order.detail//id='.$order['id'],true);
		cfc('account')->sendtwoNotice($order['mid'],$template_id,$message,$url,'groupfinish','jy_weishop',$order['id']);
	}
	public function notice_groupfail($order,$url=''){
		//拼团失败
		$template_id=cfc('account')->get_tpl_template_id('OPENTM401113750','拼团失败通知');
		if(!$order['goodstitle']){
			if(!$order['goodsid']){
				$order['goodsid']=pdo_getcolumn('jy_weishop_order_goods',array('orderid'=>$order['id']),'goodsid');
			}
			$goods=pdo_get('jy_weishop_goods',array('id'=>$order['goodsid'],'uniacid'=>$_SESSION['uniacid']),array('id','title'));
			$order['goodstitle']=$goods['title'];
		}
		$message=array(
			'first'=>array('value'=>'您好，您参加的拼团由于团已过期，拼团失败!',"color" => "#4a5077"),
			'keyword1'=>array('value'=>$order['goodstitle'],"color" => "#4a5077"),
			'keyword2'=>array('value'=>$order['price'],"color" => "#4a5077"),
			'keyword5'=>array('value'=>$order['price'],"color" => "#4a5077"),
			'remark'=>array('value'=>'您的退款已经提交处理，请留意！感谢您的参与！',"color" => "#4a5077"),
		);
		//$url=custom_url('jy_weishop_en/order.detail//id='.$order['id'],true);
		cfc('account')->sendtwoNotice($order['mid'],$template_id,$message,$url,'groupfinish','jy_weishop',$order['id']);
	}
}
